const mongoose = require('./db')
const Schema = mongoose.Schema

const cateSchema = new Schema({
    name: String,
})
const cateModel = mongoose.model('cate', cateSchema, 'cate')

const listSchema = new Schema({
    name: String,
    img: Array,
    price: Number,
    detail: String,
    courier: String,
    description: String,
    category: String, //首页分类 (最新上架，热销商品...)
    cid:{
        type: Schema.Types.ObjectId,
        ref: 'cate'
    }//分类id
})
const listModel = mongoose.model('list', listSchema, 'list')

const addressSchema = new Schema({
    name: String,
    phone: Number,
    address: String,
    fullAddress: String,
    isdefault: Boolean,

})
const addressModel = mongoose.model('address', addressSchema, 'address')

const shopListSchema = new Schema({
    num: Number,
    lid: {
        type: Schema.Types.ObjectId,
        ref: 'list'
    },
    flag: {
        type: Boolean,
        default: false
    }
})
const shopListModel = mongoose.model('shopList', shopListSchema, 'shopList')
// shopListModel.create({
//     num: 12,
//     lid: '67072f01744540818c68c19a'
// })
const loginSchema = new mongoose.Schema({
    user: String,
    password: String,
    phone: String,
    sex: String,
    image: String
})

const loginModel = mongoose.model('login', loginSchema, 'login')

const orderSchema = new mongoose.Schema({
    name: String,
    price: Number,
    img: Array,
    detail: String,
    Lid:{
        type: Schema.Types.ObjectId,
        ref: 'list'
    },
    status: {
        type: Number,
        default: 0
    }
})

const orderModel = mongoose.model('order', orderSchema, 'order')

module.exports = {
    listModel,
    shopListModel,
    addressModel,
    cateModel,
    loginModel,
    orderModel
}

